
package com.fugit.tag;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;

/**
 * Personal taglib management class. Display Header.
 * 
 * @author Jee3
 * 
 */
public class FuFile extends SimpleTagSupport {

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.servlet.jsp.tagext.SimpleTagSupport#doTag()
	 */
	@Override
	public final void doTag() throws JspException, IOException {
		
		// html/JavaScript code of servlet call 
		final String jsServletCall = "<form id=\"fileupload\" action=\"UploadServlet\" method=\"POST\" enctype=\"multipart/form-data\">"
				+ "\n"
				+ "<!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->"
				+ "\n"
				+ "<div class=\"row fileupload-buttonbar\">"
				+ "\n"
				+ "<div class=\"span7\">"
				+ "\n"
				+ "<!-- The fileinput-button span is used to style the file input field as button -->"
				+ "\n"
				+ "<span class=\"btn btn-success fileinput-button\">"
				+ "\n"
				+ "<i class=\"icon-plus icon-white\"></i>"
				+ "\n"
				+ "<span>Add files...</span>"
				+ "\n"
				+ "<input type=\"file\" name=\"files[]\" multiple>"
				+ "\n"
				+ "</span>"
				+ "\n"
				+ "<button type=\"submit\" class=\"btn btn-primary start\">"
				+ "\n"
				+ "<i class=\"icon-upload icon-white\"></i>"
				+ "\n"
				+ "<span>Start upload</span>"
				+ "\n"
				+ "</button>"
				+ "\n"
				+ "<button type=\"reset\" class=\"btn btn-warning cancel\">"
				+ "\n"
				+ "<i class=\"icon-ban-circle icon-white\"></i>"
				+ "\n"
				+ "<span>Cancel upload</span>"
				+ "\n"
				+ "</button>"
				+ "\n"
				+ "<button type=\"button\" class=\"btn btn-danger delete\">"
				+ "\n"
				+ "<i class=\"icon-trash icon-white\"></i>"
				+ "\n"
				+ "<span>Delete</span>"
				+ "\n"
				+ "</button>"
				+ "\n"
				+ "<input type=\"checkbox\" class=\"toggle\">"
				+ "\n"
				+ "</div>"
				+ "\n"
				+ "<!-- The global progress information -->"
				+ "\n"
				+ "<div class=\"span5 fileupload-progress fade\">"
				+ "\n"
				+ "<!-- The global progress bar -->"
				+ "\n"
				+ "<div class=\"progress progress-success progress-striped active\" role=\"progressbar\" aria-valuemin=\"0\" aria-valuemax=\"100\">"
				+ "\n"
				+ "<div class=\"bar\" style=\"width:0%;\"></div>"
				+ "\n"
				+ "</div>"
				+ "\n"
				+ "<!-- The extended global progress information -->"
				+ "\n"
				+ "<div class=\"progress-extended\">&nbsp;</div>"
				+ "\n"
				+ "</div>"
				+ "\n"
				+ "</div>"
				+ "\n"
				+ "<!-- The loading indicator is shown during file processing -->"
				+ "\n"
				+ "<div class=\"fileupload-loading\"></div>"
				+ "\n"
				+ "<br>"
				+ "\n"
				+ "<!-- The table listing the files available for upload/download -->"
				+ "\n"
				+ "<table role=\"presentation\" class=\"table table-striped\"><tbody class=\"files\" data-toggle=\"modal-gallery\" data-target=\"#modal-gallery\"></tbody></table>"
				+ "\n"
				+ "</form>"
				+ "\n"
				+ "<br>"
				+ "\n"
				+ " </div>"
				+ "\n"
				+ "<!-- modal-gallery is the modal dialog used for the image gallery -->"
				+ "\n"
				+ "<div id=\"modal-gallery\" class=\"modal modal-gallery hide fade\" data-filter=\":odd\">"
				+ "\n"
				+ "<div class=\"modal-header\">"
				+ "\n"
				+ "<a class=\"close\" data-dismiss=\"modal\">&times;</a>"
				+ "\n"
				+ "<h3 class=\"modal-title\"></h3>"
				+ "\n"
				+ "</div>"
				+ "\n"
				+ "<div class=\"modal-body\"><div class=\"modal-image\"></div></div>"
				+ "\n"
				+ "<div class=\"modal-footer\">"
				+ "\n"
				+ "<a class=\"btn modal-download\" target=\"_blank\">"
				+ "\n"
				+ "<i class=\"icon-download\"></i>"
				+ "\n"
				+ "<span>Download</span>"
				+ "\n"
				+ "</a>"
				+ "\n"
				+ "<a class=\"btn btn-success modal-play modal-slideshow\" data-slideshow=\"5000\">"
				+ "\n"
				+ "<i class=\"icon-play icon-white\"></i>"
				+ "\n"
				+ "<span>Slideshow</span>"
				+ "\n"
				+ "</a>"
				+ "\n"
				+ "<a class=\"btn btn-info modal-prev\">"
				+ "\n"
				+ "<i class=\"icon-arrow-left icon-white\"></i>"
				+ "\n"
				+ "<span>Previous</span>"
				+ "\n"
				+ "</a>"
				+ "\n"
				+ "<a class=\"btn btn-primary modal-next\">"
				+ "\n"
				+ "<span>Next</span>"
				+ "\n"
				+ "<i class=\"icon-arrow-right icon-white\"></i>"
				+ "\n"
				+ "</a>"
				+ "\n"
				+ "</div>"
				+ "\n"
				+ "</div>"
				+ "\n"
				+ ""
				+ "\n"
				+ "<!-- The template to display files available for upload -->"
				+ "\n"
				+ "<script id=\"template-upload\" type=\"text/x-tmpl\">"
				+ "\n"
				+ "{% for (var i=0, file; file=o.files[i]; i++) { %}"
				+ "\n"
				+ "<tr class=\"template-upload fade\">"
				+ "\n"
				+ "<td class=\"preview\"><span class=\"fade\"></span></td>"
				+ "\n"
				+ "<td class=\"name\"><span>{%=file.name%}</span></td>"
				+ "\n"
				+ "<td class=\"size\"><span>{%=o.formatFileSize(file.size)%}</span></td>"
				+ "\n"
				+ "{% if (file.error) { %}"
				+ "\n"
				+ "<td class=\"error\" colspan=\"2\"><span class=\"label label-important\">Error</span> {%=file.error%}</td>"
				+ "\n"
				+ "{% } else if (o.files.valid && !i) { %}"
				+ "\n"
				+ "<td>"
				+ "\n"
				+ "<div class=\"progress progress-success progress-striped active\" role=\"progressbar\" aria-valuemin=\"0\" aria-valuemax=\"100\" aria-valuenow=\"0\"><div class=\"bar\" style=\"width:0%;\"></div></div>"
				+ "\n"
				+ "</td>"
				+ "\n"
				+ "<td class=\"start\">{% if (!o.options.autoUpload) { %}"
				+ "\n"
				+ "<button class=\"btn btn-primary\">"
				+ "\n"
				+ "<i class=\"icon-upload icon-white\"></i>"
				+ "\n"
				+ "<span>Start</span>"
				+ "\n"
				+ "</button>"
				+ "\n"
				+ "{% } %}</td>"
				+ "\n"
				+ "{% } else { %}"
				+ "\n"
				+ "<td colspan=\"2\"></td>"
				+ "\n"
				+ "{% } %}"
				+ "\n"
				+ "<td class=\"cancel\">{% if (!i) { %}"
				+ "\n"
				+ "<button class=\"btn btn-warning\">"
				+ "\n"
				+ "<i class=\"icon-ban-circle icon-white\"></i>"
				+ "\n"
				+ "<span>Cancel</span>"
				+ "\n"
				+ "</button>"
				+ "\n"
				+ "{% } %}</td>"
				+ "\n"
				+ "</tr>"
				+ "\n"
				+ "{% } %}"
				+ "\n"
				+ "</script>"
				+ "\n"
				+ "<!-- The template to display files available for download -->"
				+ "\n"
				+ "<script id=\"template-download\" type=\"text/x-tmpl\">"
				+ "\n"
				+ "{% for (var i=0, file; file=o.files[i]; i++) { %}"
				+ "\n"
				+ "<tr class=\"template-download fade\">"
				+ "\n"
				+ "{% if (file.error) { %}"
				+ "\n"
				+ "<td></td>"
				+ "\n"
				+ "<td class=\"name\"><span>{%=file.name%}</span></td>"
				+ "\n"
				+ "<td class=\"size\"><span>{%=o.formatFileSize(file.size)%}</span></td>"
				+ "\n"
				+ "<td class=\"error\" colspan=\"2\"><span class=\"label label-important\">Error</span> {%=file.error%}</td>"
				+ "\n"
				+ "{% } else { %}"
				+ "\n"
				+ "<td class=\"preview\">{% if (file.thumbnail_url) { %}"
				+ "\n"
				+ "<a href=\"{%=file.url%}\" title=\"{%=file.name%}\" rel=\"gallery\" download=\"{%=file.name%}\"><img src=\"{%=file.thumbnail_url%}\"></a>"
				+ "\n"
				+ "{% } %}</td>"
				+ "\n"
				+ "<td class=\"name\">"
				+ "\n"
				+ "<a href=\"{%=file.url%}\" title=\"{%=file.name%}\" rel=\"{%=file.thumbnail_url&&'gallery'%}\" download=\"{%=file.name%}\">{%=file.name%}</a>"
				+ "\n"
				+ "</td>"
				+ "\n"
				+ "<td class=\"size\"><span>{%=o.formatFileSize(file.size)%}</span></td>"
				+ "\n"
				+ "<td colspan=\"2\"></td>"
				+ "\n"
				+ "{% } %}"
				+ "\n"
				+ "<td class=\"delete\">"
				+ "\n"
				+ "<button class=\"btn btn-danger\" data-type=\"{%=file.delete_type%}\" data-url=\"{%=file.delete_url%}\"{% if (file.delete_with_credentials) { %} data-xhr-fields='{\"withCredentials\":true}'{% } %}>"
				+ "\n"
				+ "<i class=\"icon-trash icon-white\"></i>"
				+ "\n"
				+ "<span>Delete</span>"
				+ "\n"
				+ "</button>"
				+ "\n"
				+ "<input type=\"checkbox\" name=\"delete\" value=\"1\">"
				+ "\n"
				+ "</td>"
				+ "\n"
				+ "</tr>"
				+ "\n"
				+ "{% } %}"
				+ "\n"
				+ "</script>";

		getJspContext().getOut().write(jsServletCall);
	}

}
